﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkflowCore.Interface;
using WorkflowCore.Models;

namespace Workflow2211A.Consol.Steps
{
    /// <summary>
    /// 【ForEach步骤】多人审批
    /// </summary>
    public class AuditStep : StepBody
    {
        public override ExecutionResult Run(IStepExecutionContext context)
        {
            if (!context.ExecutionPointer.EventPublished)
            {
                //context.Item可以拿到Foreach中的值
                Console.WriteLine("等待第{0}个人审批",context.Item);
                //会出的问题：一个人审批完之后，会把其他人的审批事件都消费了
                return ExecutionResult.WaitForEvent("MyEvent",context.Workflow.Id + context.Item,DateTime.Now);
            }
            //获取审批意见
            var eventData = context.ExecutionPointer.EventData;
            Console.WriteLine("第{0}个人的审批意见是：{1}",context.Item,eventData);
            return ExecutionResult.Next();
        }
    }
}
